import operate from '@dfeidao/atom-nodejs/db/operate';
import log from '@dfeidao/atom-nodejs/logger/log';
import sys_date from '@dfeidao/atom-nodejs/msg/sys-date';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';

interface Message {
	msgid: string;
	productid: string;
}

interface IWebResult {
	data: unknown;
	cookie?: {
		[name: string]: string;
	} | null;
	content_type?: string;
	headers?: {
		[key: string]: string[];
	};
	attachment?: string;
	redirect?: string;
	status_code?: number;
}

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	log('Service begin path:mine-purse/zj-000004/s004,action_id:' + action_id);

	log('Service end path:mine-purse/zj-000004/s004,action_id:' + action_id);

	const { update, exec } = operate(action_id, session_id, systemid);
	const dateTime = sys_date(action_id, session_id);
	update('msg_receiver', { msgid: message.msgid }, { is_read: '1', read_time: dateTime });
	const res_2 = await exec();
	return { data: res_2 };
}
